// page/doctorPatientInteraction/doctorPatientInteraction.js
var http = require("../../utils/http.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputValue: "",
    mesArray: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var header = {
    token: "ABCD0001"
    }
    http.getReq("/spc/sns/infos?pageSize=10&pageNo=1", "", header,function(res){
       // console.log(res);
        var list = [];
        for(let i = 0;i<res.length;i++){
          var myNewMes = {};
          myNewMes.mesType = "myItem";
          var jsons = {};
          jsons.mes = res[i].content;
          jsons.createDatetime = res[i].createDatetime;
          myNewMes.mesitem = jsons;
          
          list.push(myNewMes);
        }
        that.setData({
          mesArray: list
        });
     
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value,
      inputSign: true
    });

  },
  sendMes: function () {
    var that = this;
    var oriMesArr = this.data.mesArray;
    var newMes = this.data.inputValue;
    if (newMes != "") {
      var header = {
        token: "ABCD0001",
        Accept:"text/plain",
        "Content-Type": "application/x-www-form-urlencoded"
      };
      var date = "snsContent=" + newMes;
      http.postReq("/spc/sns/sns-info",date,header,function(res,code){
        if(code = "200"){
          console.log(res);
          var myNewMes = {
            mesType: "myItem",
            mesitem: {
              mes: newMes
            }
          };
          oriMesArr.push(myNewMes);
          that.setData({ mesArray: oriMesArr });
          that.setData({ inputValue: "" });
        }
      });
    }
  }
})